<?php

$firebaseHost = 'https://swagmoney.firebaseio.com/';
$secretKey = 'eqH4AI4FiCksNkOm0ZaLd2n5MNMkQGMlOuDUAMyW';

$firebase = new Firebase($firebaseHost, $secretKey);

function setFirebaseValue($path, $value) {
	global $firebase;
	$firebase->set($path, $value);
}

function getFirebaseValue($path) {
	global $firebase;
	$value = $firebase->get($path);
	eval('$value = ' . $value . ";");
	return $value;
}

function authorizeToken($token, $id) {
	$path = 'users/' . $id . '/token';
	return $token == getFirebaseValue($path);
}

function doesUserExist($id) {
	$path = 'users/' . $id . '/token';
	return getFirebaseValue($path) != false;
}

function getUserBalance($id) {
	$path = 'users/' . $id . '/balance';
	return getFirebaseValue($path);
}

function setUserBalance($id, $balance) {
	$path = '/users/' . $id . '/balance';
	setFirebaseValue($path, $balance);
}

function getBlocksMined() {
	$path = 'blocksMined';
	return getFirebaseValue($path);
}

function incrementBlocksMined() {
	global $blocksMined;
	$path = 'blocksMined';
	$blocksMined++;
	setFirebaseValue($path, $blocksMined);
}

function getBlockLocation() {
	$path = 'blockLocation';
	return getFirebaseValue($path);
}

function setBlockLocation($newLocation) {
	$path = 'blockLocation';
	setFirebaseValue($path, $newLocation);
}